package com.example.parcelabledemo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import java.io.InputStream;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity implements OnClickListener{

    private Button sendobj;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        sendobj = (Button) findViewById(R.id.sendobj);
        sendobj.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Log.d("--Telink--","onClick(MainActivity.java:32)-->>");
        if (v.getId() == R.id.sendobj) {
            //ObjBean bean = new ObjBean();
            //bean.setId(1);
            //bean.setName("Android smart Phone");
            //bean.setPrice(999.99);

            InputStream is = getResources().openRawResource(R.raw.img);
            Bitmap bit = BitmapFactory.decodeStream(is);
            //bean.setBitmap(bit);
            ObjBean bean = new ObjBean(1, "Android smart phone price is: ", 999.98, bit);

            ParcelableUtil pUtil = new ParcelableUtil(bean);

            Intent intent = new Intent(MainActivity.this, AnotherActivity.class);
            intent.putExtra("objbean", pUtil);//将ParcelableUtil对象put到intent中
            //intent.setExtrasClassLoader(ObjBean.class.getClassLoader());
            Log.d("--Telink--","onClick(MainActivity.java:48)-->>");
            startActivity(intent);
        }
    }

}